package lhl.task;

import com.ejlchina.searcher.BeanSearcher;
import com.ejlchina.searcher.MapSearcher;
import com.ejlchina.searcher.param.Operator;
import com.ejlchina.searcher.util.MapUtils;
import lhl.entity.Table_test;
import lhl.vo.Table_testVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class TaskDemo {

	/**
	 * 注入 Map 检索器，它检索出来的数据以 Map 对象呈现
	 */
	@Autowired
	private MapSearcher mapSearcher;
	/**
	 * 注入 Bean 检索器，它检索出来的数据以 泛型 对象呈现
	 */
	@Autowired
	private BeanSearcher beanSearcher;


	//@Scheduled(cron = "0/1 * * * * *")
	public void asyncTask() {

		log.info("log________hh_");
		Map<String, Object> params = MapUtils.builder()
				.page(0, 15)                    // 第 0 页，每页 15 条（推荐写法）
				.build();
		List<Table_test> taskDemos = beanSearcher.searchList(Table_test.class, params);
		log.info(taskDemos.toString());
	}


	//@Scheduled(cron = "0/2 * * * * *")
	public void asyncTask2() {

		log.info("log________hh_");
		Map<String, Object> params = MapUtils.builder()

				//.field(Table_test::getColumn_1, 1) // 过滤：status = 1
				.field(Table_test::getColumn_2, "jack").op(Operator.Contain) // 过滤：name = 'Jack' (case ignored)
				//.field(Table_test::getColumn_3, 20, 30).op(Operator.Between) // 过滤：age between 20 and 30
				.orderBy(Table_test::getColumn_4, "asc") // 排序：，从小到大
				.page(0, 15) // 分页：第 0 页, 每页 15 条
				.build();
		List<Table_test> taskDemos = beanSearcher.searchList(Table_test.class, params);
		log.info(taskDemos.toString());
	}

	//@Scheduled(cron = "0/2 * * * * *")
	public void asyncTask3() {

		log.info("log________hh_");
		ArrayList<Integer> integers = new ArrayList<>();
		integers.add(1);
		Map<String, Object> params = MapUtils.builder()
				.field(Table_test::getColumn_1, integers).op(Operator.InList) // 过滤：in list
				.field(Table_test::getColumn_4).op(Operator.NotEmpty)  // 1=''
				.field(Table_test::getColumn_3).op(Operator.NotNull)  // not noll
				.orderBy(Table_test::getColumn_4, "asc") // 排序：，从小到大
				.page(0, 15) // 分页：第 0 页, 每页 15 条
				.build();
		List<Table_test> taskDemos = beanSearcher.searchList(Table_test.class, params);

		log.info(taskDemos.toString());
	}


	@Scheduled(cron = "0/5 * * * * *")
	public void asyncTask5() {

		Map<String, Object> params = MapUtils.builder()
				.page(0, 15)                    // 第 0 页，每页 15 条（推荐写法）
				.build();
		List<Table_testVo> taskDemos = beanSearcher.searchList(Table_testVo.class, params);
		log.info(taskDemos.toString());
	}
}
